﻿using System;
using System.Collections.Generic;
using Battle.Engine.LogicModel;

namespace Battle.Engine
{
    //-------------------------------------------------
    //        (3)   11   12   13   14   15
    //        (2)   6    7    8    9    10
    //        (1)   1    2    3    4    5
    //
    //Camera
    //
    //        (1)   1    2    3    4    5
    //        (2)   6    7    8    9    10
    //        (3)   11   12   13   14   15
    //-------------------------------------------------

    public class FRange
    {

        public List<FActor> SelectTargetActors(bool isSkill, int strategy, FActor actor, FActor tactor, List<SelectLimitCondition> conditions, EngineData data)
        {
            int select = strategy;
            FPlayer targetPlayer;
            if (select > 100)
            {
                select = select - 100;
                targetPlayer = data.getPlayerByCampType(actor.player.camp);
            }
            else
            {
                targetPlayer = data.getPlayerByCampType(actor.player.enemyCamp);
            }

            List<FActor> targetActors = new List<FActor>();
            //过滤当前已经死亡的人
            foreach (var t in targetPlayer.actors)
            {
                if(t != null && t.state != FActorState.DEAD)
                {
                    bool flag = false;
                    for(int i = 0; i < targetActors.Count; i++)
                    {
                        if(targetActors[i].MainPosition.ToFPID() > t.MainPosition.ToFPID())
                        {
                            targetActors.Insert(i,t);
                            flag = true;
                            break;
                        }
                    }
                    if(flag == false)
                    {
                        targetActors.Add(t);
                    }
                }
            }
            List<FActor> selectActors = new List<FActor>();
            switch ((SelectStrategy)select)
            {
                case SelectStrategy.SELF: //自己
                    {
                        selectActors.Add(actor);
                    }
                    break;
                case SelectStrategy.SAME_AS_LAST_RELEASE: //与上次release一样
                    {
                        //只技能目标选择生效，在外部进行处理，正常不会跑到这里
                        Debug.LogError("SelectTargetActors--->Undo SelectStrategy outside:" + "SAME_AS_LAST_RELEASE");
                    }
                    break;
                case SelectStrategy.SAME_AS_CAST: //目标
                    {
                        if (data.IsActorMatchCondition(tactor, tactor, conditions))
                        {//判断是否满足限制条件
                            selectActors.Add(tactor);
                        }
                    }
                    break;
                case SelectStrategy.FIRST_ONE: //第一个（位置顺序）
                    {
                        if (tactor != null)
                        {
                            selectActors.Add(tactor);
                        }
                        else
                        {
                            var find = GetFirstActor(targetActors, tactor, conditions, data);
                            if (find != null)
                            {
                                selectActors.Add(find);
                            }
                        }
                    }
                    break;
                case SelectStrategy.FIRST_RANDOM1: //第一个加随机一个
                    {
                        //先取第一个
                        var ignoreUIDs = new List<string>();
                        if (tactor != null)
                        {
                            selectActors.Add(tactor);
                            ignoreUIDs.Add(tactor.uniqueId);
                        }
                        else
                        {
                            var find = GetFirstActor(targetActors, tactor, conditions, data);
                            if (find != null)
                            {
                                selectActors.Add(find);
                                ignoreUIDs.Add(find.uniqueId);
                            }
                        }
                        //再随机一个
                        var randomTargets = data.range.GetRandomActors(1, targetActors, tactor, ignoreUIDs, conditions, data);
                        selectActors.AddRange(randomTargets);
                    }
                    break;
                case SelectStrategy.FIRST_RANDOM2: //第一个加随机两个
                    {
                        //先取第一个
                        var ignoreUIDs = new List<string>();
                        if (tactor != null)
                        {
                            selectActors.Add(tactor);
                            ignoreUIDs.Add(tactor.uniqueId);
                        }
                        else
                        {
                            var find = GetFirstActor(targetActors, tactor, conditions, data);
                            if (find != null)
                            {
                                selectActors.Add(find);
                                ignoreUIDs.Add(find.uniqueId);
                            }
                        }
                        //再随机两个
                        var randomTargets = GetRandomActors(2, targetActors, tactor, ignoreUIDs, conditions, data);
                        selectActors.AddRange(randomTargets);

                    }
                    break;
                case SelectStrategy.RANDOM1: //随机一个
                    {
                        var ignoreUIDs = new List<string>();
                        var randomTargets = GetRandomActors(1, targetActors, tactor, ignoreUIDs, conditions, data);
                        selectActors.AddRange(randomTargets);
                    }
                    break;
                case SelectStrategy.RANDOM2: //随机两个
                    {
                        var ignoreUIDs = new List<string>();
                        var randomTargets = GetRandomActors(2, targetActors, tactor, ignoreUIDs, conditions, data);
                        selectActors.AddRange(randomTargets);
                    }
                    break;
                case SelectStrategy.RANDOM3: //随机三个
                    {
                        var ignoreUIDs = new List<string>();
                        var randomTargets = GetRandomActors(3, targetActors, tactor, ignoreUIDs, conditions, data);
                        selectActors.AddRange(randomTargets);
                    }
                    break;
                case SelectStrategy.LAST_ONE: //最后一个
                    {
                        var find = GetLastActor(targetActors, tactor, conditions, data);
                        if (find != null)
                        {
                            selectActors.Add(find);
                        }
                    }
                    break;
                case SelectStrategy.ALL: //全体
                    {
                        foreach (var target in targetActors)
                        {
                            if (data.IsActorMatchCondition(target, tactor, conditions))
                            {//判断是否满足限制条件
                                selectActors.Add(target);
                            }
                        }
                    }
                    break;
                case SelectStrategy.FRONT_ROW: //前排
                    {
                        var targets = GetRow1ActorsByRow(FPosition.FRONT_ROW, targetActors, tactor, conditions, data);
                        selectActors.AddRange(targets);
                    }
                    break;
                case SelectStrategy.MIDDLE_ROW: //中排
                    {
                        var targets = GetRow1ActorsByRow(FPosition.MIDDLE_ROW, targetActors, tactor, conditions, data);
                        selectActors.AddRange(targets);
                    }
                    break;
                case SelectStrategy.BACK_ROW: //后排
                    {
                        var targets = GetRow1ActorsByRow(FPosition.BACK_ROW, targetActors, tactor, conditions, data);
                        selectActors.AddRange(targets);
                    }
                    break;
                case SelectStrategy.FRONT_TWO_ROWS: //固定前两排
                    {
                        var targets = GetFixedRow2ActorsByRow(FPosition.FRONT_ROW, targetActors, tactor, conditions, data);
                        selectActors.AddRange(targets);
                    }
                    break;
                case SelectStrategy.BACK_TWO_ROWS: //固定后两排
                    {
                        var targets = GetFixedRow2ActorsByRow(FPosition.BACK_ROW, targetActors, tactor, conditions, data);
                        selectActors.AddRange(targets);
                    }
                    break;
                case SelectStrategy.MIN_HP: //血量最少
                    {
                        FActor target = null;
                        foreach (var a in targetActors)
                        {
                            if (target == null)
                            {
                                if (data.IsActorMatchCondition(a, tactor, conditions))
                                {
                                    target = a;
                                }
                            }
                            else if(a.attribute.hp < target.attribute.hp)
                            {
                                if (data.IsActorMatchCondition(a, tactor, conditions))
                                {
                                    target = a;
                                }
                            }
                        }
                        if (target != null)
                        {
                            selectActors.Add(target);
                        }
                    }
                    break;
                case SelectStrategy.MAX_HP: //血量最多
                    {
                        FActor target = null;
                        foreach (var a in targetActors)
                        {
                            if (target == null)
                            {
                                if (data.IsActorMatchCondition(a, tactor, conditions))
                                {
                                    target = a;
                                }
                            }
                            else if(a.attribute.hp > target.attribute.hp)
                            {
                                if (data.IsActorMatchCondition(a, tactor, conditions))
                                {
                                    target = a;
                                }
                            }
                        }
                        if (target != null)
                        {
                            selectActors.Add(target);
                        }
                    }
                    break;
                case SelectStrategy.OPPOSITE: //正对位,对位无人则选第一个
                    {
                        int fpid = actor.MainPosition.ToFPID() % FPosition.COL;
                        FActor target = data.GetActorByFpid(fpid, targetActors, tactor, conditions);
                        //如果没找到目标，往后找
                        if (target == null)
                        {
                            for (int i = 0; i < 3; ++i)
                            {
                                fpid = fpid + 5;
                                FActor find = targetPlayer.GetActorByFpid(fpid, tactor, conditions, data);
                                if (find != null && find.state != FActorState.DEAD)
                                {
                                    target = find;
                                }
                                if (target != null)
                                    break;
                            }
                        }
                        //如果还没找到,使用默认目标
                        if (target == null)
                        {
                            if (tactor != null)
                            {
                                target = tactor;
                            }
                            else
                            {
                                target = GetFirstActor(targetActors, tactor, conditions, data);
                            }
                        }
                        if (target != null)
                        {
                            selectActors.Add(target);
                        }
                    }
                    break;
                case SelectStrategy.FIRST_ONE_LINE: //第一人所在的直线列
                    {
                        FActor target = tactor;
                        if (target == null)
                        {
                            target = GetFirstActor(targetActors, tactor, conditions, data);
                            if (target == null)
                                break;
                        }
                        selectActors.Add(target);
                        int fpid = tactor.MainPosition.ToFPID();
                        for (int i = 0; i < 3; ++ i)
                        {
                            fpid = fpid + 5;
                            FActor find = targetPlayer.GetActorByFpid(fpid, tactor, conditions, data);
                            if (find != null && find.state != FActorState.DEAD)
                            {
                                selectActors.Add(find);
                            }
                        }
                    }
                    break;
                case SelectStrategy.FIRST_ONE_FRONT_TWO_ROWS: //第一人所在前两排
                    {
                        FActor target = tactor;
                        if (target == null)
                        {
                            target = GetFirstActor(targetActors, tactor, conditions, data);
                            if (target == null)
                                break;
                        }
                        if (target.MainPosition.row == 1)
                        {
                            var targets = GetFixedRow2ActorsByRow(FPosition.FRONT_ROW, targetActors, tactor, conditions, data);
                            selectActors.AddRange(targets);
                        }
                        else
                        {
                            var targets = GetFixedRow2ActorsByRow(FPosition.BACK_ROW, targetActors, tactor, conditions, data);
                            selectActors.AddRange(targets);
                        }
                    }
                    break;
                case SelectStrategy.FIRST_ONE_SQUARED: //第一人为中心的九宫格
                    {
                        FActor target = tactor;
                        if (target == null)
                        {
                            target = GetFirstActor(targetActors, tactor, conditions, data);
                            if (target == null)
                                break;
                        }
                        int col = target.MainPosition.col;
                        int row = target.MainPosition.row;
                        int[] offsetcol = { -1, 0, 1, -1, 0, 1, -1, 0, 1 };
                        int[] offsetrow = { -1, -1, -1, 0, 0, 0, 1, 1, 1 };
                        for (int i = 0; i <= 8; ++i)
                        {
                            int findcol = col + offsetcol[i];
                            int findrow = row + offsetrow[i];
                            if (findcol < 1 || findcol >= 6)
                                continue;
                            if (findrow < 1 || findrow >= 4)
                                continue;
                            FPosition findpos = new FPosition(findcol, findrow, 0);
                            FActor find = targetPlayer.GetActorByFpid(findpos.ToFPID(), tactor, conditions, data);
                            if(find != null && find.state != FActorState.DEAD)
                            {
                                selectActors.Add(find);
                            }
                        }
                    }
                    break;
                case SelectStrategy.OPPOSITE_ONE_SQUARED://对位人为中心的九宫格,对位无人则取第一人为中心
                    {
                        int fpid = actor.MainPosition.ToFPID() % FPosition.COL;
                        FActor target = data.GetActorByFpid(fpid, targetActors, tactor, conditions);
                        //如果没找到目标，往后找
                        if (target == null)
                        {
                            for (int i = 0; i < 3; ++i)
                            {
                                fpid = fpid + 5;
                                FActor find = targetPlayer.GetActorByFpid(fpid, tactor, conditions, data);
                                if (find != null && find.state != FActorState.DEAD)
                                {
                                    target = find;
                                }
                                if (target != null)
                                    break;
                            }
                        }
                        //如果还没找到,使用默认目标
                        if (target == null)
                        {
                            if (tactor != null)
                            {
                                target = tactor;
                            }
                            else
                            {
                                target = GetFirstActor(targetActors, tactor, conditions, data);
                            }
                            if (target == null)
                                break;
                        }
                        int col = target.MainPosition.col;
                        int row = target.MainPosition.row;
                        int[] offsetcol = { -1, 0, 1, -1, 0, 1, -1, 0, 1 };
                        int[] offsetrow = { -1, -1, -1, 0, 0, 0, 1, 1, 1 };
                        for (int i = 0; i <= 8; ++i)
                        {
                            int findcol = col + offsetcol[i];
                            int findrow = row + offsetrow[i];
                            if (findcol < 1 || findcol >= 6)
                                continue;
                            if (findrow < 1 || findrow >= 4)
                                continue;
                            FPosition findpos = new FPosition(findcol, findrow, 0);
                            FActor find = targetPlayer.GetActorByFpid(findpos.ToFPID(), tactor, conditions, data);
                            if (find != null && find.state != FActorState.DEAD)
                            {
                                selectActors.Add(find);
                            }
                        }
                    }
                    break;
                case SelectStrategy.LAST_ONE_SQUARED://最后一人为中心的九宫格
                    {
                        FActor target = tactor;
                        if (target == null)
                        {
                            target = GetLastActor(targetActors, tactor, conditions, data);
                            if (target == null)
                                break;
                        }
                        int col = target.MainPosition.col;
                        int row = target.MainPosition.row;
                        int[] offsetcol = { -1, 0, 1, -1, 0, 1, -1, 0, 1 };
                        int[] offsetrow = { -1, -1, -1, 0, 0, 0, 1, 1, 1 };
                        for (int i = 0; i <= 8; ++i)
                        {
                            int findcol = col + offsetcol[i];
                            int findrow = row + offsetrow[i];
                            if (findcol < 1 || findcol >= 6)
                                continue;
                            if (findrow < 1 || findrow >= 4)
                                continue;
                            FPosition findpos = new FPosition(findcol, findrow, 0);
                            FActor find = targetPlayer.GetActorByFpid(findpos.ToFPID(), tactor, conditions, data);
                            if (find != null && find.state != FActorState.DEAD)
                            {
                                selectActors.Add(find);
                            }
                        }
                    }
                    break;
                case SelectStrategy.RANDOM_WITHOUT_SELECT: //排除已命中人后进行随机一人，若全部命中过，则清空已命中再随机
                    {
                        var ignoreUIDs = new List<string>();
                        foreach(var a in actor.behitActors)
                        {
                            ignoreUIDs.Add(a.uniqueId);
                        }
                        //排除已命中，随机一人
                        var randomTargets = data.range.GetRandomActors(1, targetActors, tactor, ignoreUIDs, conditions, data);
                        if(randomTargets.Count == 0)
                        {
                            actor.behitActors.Clear();
                            ignoreUIDs.Clear();
                            randomTargets = data.range.GetRandomActors(1, targetActors, tactor, ignoreUIDs, conditions, data);
                        }
                        selectActors.AddRange(randomTargets);
                    }
                    break;
                case SelectStrategy.MORE_HP: //血量比自己多
                    {
                        foreach (var a in targetActors)
                        {
                            if (a.attribute.hp > actor.attribute.hp)
                            {
                                if (data.IsActorMatchCondition(a, tactor, conditions))
                                {
                                    selectActors.Add(a);
                                }
                            }
                        }

                    }
                    break;
                case SelectStrategy.MAX_ATT: //攻击最高
                    {
                        FActor target = null;
                        foreach (var a in targetActors)
                        {
                            if (target == null)
                            {
                                if (data.IsActorMatchCondition(a, tactor, conditions))
                                {
                                    target = a;
                                }
                            }
                            else if(a.attribute.att.value > target.attribute.att.value)
                            {
                                if (data.IsActorMatchCondition(a, tactor, conditions))
                                {
                                    target = a;
                                }
                            }
                        }
                        if (target != null)
                        {
                            selectActors.Add(target);
                        }
                    }
                    break;
                case SelectStrategy.MIN_PDEF: //物理防御最低
                    {
                        FActor target = null;
                        foreach (var a in targetActors)
                        {
                            if (target == null)
                            {
                                if (data.IsActorMatchCondition(a, tactor, conditions))
                                {
                                    target = a;
                                }
                            }
                            else if(a.attribute.pdef.value < target.attribute.pdef.value)
                            {
                                if (data.IsActorMatchCondition(a, tactor, conditions))
                                {
                                    target = a;
                                }
                            }
                        }
                        if (target != null)
                        {
                            selectActors.Add(target);
                        }
                    }
                    break;
                case SelectStrategy.MIN_MDEF: //魔法防御最低
                    {
                        FActor target = null;
                        foreach (var a in targetActors)
                        {
                            if (target == null)
                            {
                                if (data.IsActorMatchCondition(a, tactor, conditions))
                                {
                                    target = a;
                                }
                            }
                            else if(a.attribute.mdef.value < target.attribute.mdef.value)
                            {
                                if (data.IsActorMatchCondition(a, tactor, conditions))
                                {
                                    target = a;
                                }
                            }
                        }
                        if (target != null)
                        {
                            selectActors.Add(target);
                        }
                    }
                    break;
                case SelectStrategy.FIRST_DIE:
                    //直接取死亡人物的数据，不需要过滤任何条件
                    for (int i = 0; i < targetPlayer.deadActors.Count; i++)
                    {
                        if (targetPlayer.deadActors[i].isRebound == false)
                        {
                            selectActors.Add(targetPlayer.deadActors[i]);
                            break;
                        }
                    }
                    break;
                case SelectStrategy.MAX_MINUS_HP: //减血最多
                    {
                        FActor target = null;
                        foreach (var a in targetActors)
                        {
                            if (target == null)
                            {
                                if (data.IsActorMatchCondition(a, tactor, conditions))
                                {
                                    target = a;
                                }
                            }
                            else if ((a.attribute.maxHp-a.attribute.hp) > (target.attribute.maxHp-target.attribute.hp))
                            {
                                if (data.IsActorMatchCondition(a, tactor, conditions))
                                {
                                    target = a;
                                }
                            }
                        }
                        if (target != null)
                        {
                            selectActors.Add(target);
                        }
                    }
                    break;
                default:
                    {
                        //未处理的选择范围类型
                        Debug.LogError("SelectTargetActors--->Unknown SelectStrategy:" + select);
                    }
                    break;
            }
            if (isSkill && selectActors.Count == 0)
            {//技能选取目标不能为空
                FActor firstActor = GetFirstAlifeActor(targetActors, data);
                if(firstActor == null)
                {
                    Debug.LogError("SelectTargetActors--->There is a skill cannot find a target:" + select);
                }
                else
                {
                    selectActors.Add(firstActor);
                }
            }
            return selectActors;
        }

        public FActor GetFirstActor(List<FActor> targetActors, FActor tactor, List<SelectLimitCondition> conditions, EngineData data)
        {
            FActor find = null;
            foreach (var actor in targetActors)
            {
                if (find == null)
                {
                    if (data.IsActorMatchCondition(actor, tactor, conditions))
                    {
                        find = actor;
                    }
                }
                else if (actor.MainPosition.ToFPID() < find.MainPosition.ToFPID())
                {
                    if (data.IsActorMatchCondition(actor, tactor, conditions))
                    {
                        find = actor;
                    }
                }
            }
            if(find == null)
            {//过滤隐身限制，再取一遍
                find = GetFirstActorIgnoreInvisible(targetActors, tactor, conditions, data);
            }
            return find;
        }

        public FActor GetFirstActorIgnoreInvisible(List<FActor> targetActors, FActor tactor, List<SelectLimitCondition> conditions, EngineData data)
        {
            List<SelectLimitCondition> newconditions = new List<SelectLimitCondition>();
            //先把条件过滤隐身
            for (int i = 0; i < conditions.Count; i++)
            {
                if (conditions[i] != SelectLimitCondition.NoInvisible)
                {
                    newconditions.Add(conditions[i]);
                }
            }
            FActor find = null;
            foreach (var actor in targetActors)
            {
                if (find == null)
                {
                    if (data.IsActorMatchCondition(actor, tactor, newconditions))
                    {
                        find = actor;
                    }
                }
                else if (actor.MainPosition.ToFPID() < find.MainPosition.ToFPID())
                {
                    if (data.IsActorMatchCondition(actor, tactor, newconditions))
                    {
                        find = actor;
                    }
                }
            }
            return find;
        }

        public FActor GetFirstAlifeActor(List<FActor> targetActors, EngineData data)
        {
            FActor find = null;
            foreach (var actor in targetActors)
            {
                if (find == null)
                {
                    if (actor.state != FActorState.DEAD)
                    {
                        find = actor;
                    }
                }
                else if (actor.MainPosition.ToFPID() < find.MainPosition.ToFPID())
                {
                    if (actor.state != FActorState.DEAD)
                    {
                        find = actor;
                    }
                }
            }
            return find;
        }

        public FActor GetLastActor(List<FActor> targetActors, FActor tactor, List<SelectLimitCondition> conditions, EngineData data)
        {
            FActor find = null;
            foreach (var actor in targetActors)
            {
                if (find == null)
                {
                    if (data.IsActorMatchCondition(actor, tactor, conditions))
                    {
                        find = actor;
                    }
                }
                else if(actor.MainPosition.ToFPID() > find.MainPosition.ToFPID())
                {
                    if (data.IsActorMatchCondition(actor, tactor, conditions))
                    {
                        find = actor;
                    }
                }
            }
            return find;
        }

        /// <summary>
        /// 获取一排人，如果当前排无人则默认顺延
        /// </summary>
        /// <param name="fromRow"></param>
        /// <param name="actors"></param>
        /// <param name="conditions"></param>
        /// <returns></returns>
        public List<FActor> GetRow1ActorsByRow(int fromRow, List<FActor> actors, FActor tactor, List<SelectLimitCondition> conditions, EngineData data)
        {
            int[] row = { 1, 2, 3 };
            if (fromRow == FPosition.FRONT_ROW)
            {
                row[0] = 1;
                row[1] = 2;
                row[2] = 3;
            }
            else if (fromRow == FPosition.MIDDLE_ROW)
            {
                row[0] = 2;
                row[1] = 1;
                row[2] = 3;
            }
            else if (fromRow == FPosition.BACK_ROW)
            {
                row[0] = 3;
                row[1] = 2;
                row[2] = 1;
            }
            List<FActor> targetActors = new List<FActor>();
            for (int i = 0; i < 3; i++)
            {
                foreach (var actor in actors)
                {
                    if (actor.IsDetectionInRow(row[i]))
                    {
                        if (data.IsActorMatchCondition(actor, tactor, conditions))
                        {//判断是否满足限制条件
                            targetActors.Add(actor);
                        }
                    }
                }
                if (targetActors.Count > 0)
                {
                    break;
                }
            }
            return targetActors;
        }

        /// <summary>
        /// 获取前两排人，或者获取后两排人
        /// </summary>
        /// <param name="fromRow"></param>
        /// <param name="actors"></param>
        /// <param name="conditions"></param>
        /// <returns></returns>
        public List<FActor> GetFixedRow2ActorsByRow(int fromRow, List<FActor> actors, FActor tactor, List<SelectLimitCondition> conditions, EngineData data)
        {
            int[] row = { 1, 2 };
            if (fromRow == FPosition.FRONT_ROW)
            {
                row[0] = 1;
                row[1] = 2;
            }
            else if (fromRow == FPosition.BACK_ROW)
            {
                row[0] = 2;
                row[1] = 3;
            }

            List<FActor> targetActors = new List<FActor>();
            for (int i = 0; i < 2; i++)
            {
                foreach (var actor in actors)
                {
                    if (actor.IsDetectionInRow(row[i]))
                    {
                        if (data.IsActorMatchCondition(actor, tactor, conditions))
                        {//判断是否满足限制条件
                            targetActors.Add(actor);
                        }
                    }
                }
            }

            return targetActors;
        }

        public List<FActor> GetRandomActors(int count, List<FActor> actors, FActor tactor, List<string> ignoreActorUIDs, List<SelectLimitCondition> conditions, EngineData data)
        {
            List<FActor> targetActors = new List<FActor>();
            List<FActor> selectActors = new List<FActor>();
            foreach (var actor in actors)
            {//筛选满足条件的人物
                if (data.IsActorMatchCondition(actor, tactor, conditions) && !ignoreActorUIDs.Contains(actor.uniqueId))
                {
                    selectActors.Add(actor);
                }
            }
            for (int i = 0; i < count; i++)
            {
                if (selectActors.Count > 0)
                {
                    int randomIndex = data.random.Range(0, selectActors.Count);
                    var selectActor = selectActors[randomIndex];
                    targetActors.Add(selectActor);
                    selectActors.Remove(selectActor);
                }
                else
                {
                    break;
                }
            }
            return targetActors;
        }
    }
}
